package com.wfs.myapp.utils;

import com.github.benmanes.caffeine.cache.Cache;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class CaffeineUtils {


    private static Cache<String, Object> userCaffeineCache;
    private static Cache<String, Object> userTokenCaffeineCache;

    @Resource
    public void setUserCaffeineCache(Cache<String, Object> userCaffeineCache) {
        CaffeineUtils.userCaffeineCache = userCaffeineCache;
    }

    @Resource
    public void setUserTokenCaffeineCache(Cache<String, Object> userTokenCaffeineCache) {
        CaffeineUtils.userTokenCaffeineCache = userTokenCaffeineCache;
    }

    public static void put(String key, Object value) {
        userCaffeineCache.put(key, value);
    }

    public static Object get(String key) {
        return userCaffeineCache.asMap().get(key);
    }

    public static void putToken(String key, Object value) {
        userTokenCaffeineCache.put(key, value);
    }

    public static Object getToken(String key) {
        return userTokenCaffeineCache.asMap().get(key);
    }
}

